import { defineComponent } from 'vue';
import skinMixIn from '@/common/mixin/skinMixIn';
import { useTabbar } from './customTabbar';
import { useLayout, useCurrentInstance } from '@/common/hooks';
// #ifdef PRIVATE || SUBSCRIPTION
import { wxAppMessageShareData, wxTimelineShareData, getShareLink } from '@/common/wxInit';
// #endif
import type { MpShare } from '@/common/utils';

export default defineComponent({
	mixins: [skinMixIn],
	props: {
		index: {
			type: String,
			required: true
		}
	},
	// #ifdef MP-WEIXIN
	// 将自定义节点设置成虚拟的，更加接近Vue组件的表现，能更好的使用e-flex属性
	options: {
		virtualHost: true
	},
	// #endif
	setup(props) {
		const ctx = useCurrentInstance();
		const { onShow } = useTabbar(props.index);

		const { mpShare } = useLayout(ctx);

		onShow(() => {
			let _mpShare = mpShare.value;
			// #ifdef PRIVATE || SUBSCRIPTION
			if (Object.keys(_mpShare).length === 0) {
				_mpShare = {
					title: '', // 分享标题
					desc: '', // 分享描述
					link: getShareLink(), // 分享链接
					imgUrl: '' // 分享图标
				};
			}
			wxAppMessageShareData(_mpShare as MpShare);
			wxTimelineShareData(_mpShare as MpShare);
			// #endif
			uni.$endless.mpShare = _mpShare;
		});

		return {};
	}
});
